
import paramiko
import datetime
import os

hostname = '172.16.0.164'
username = 'root'
password = ''
port = 22

def write_msg(msg, remote_path):
    print "写入",msg
    try:
        t = paramiko.Transport((hostname, port))
        print "start",t
        key=paramiko.RSAKey.from_private_key_file("/root/.ssh/id_rsa")
        t.connect(username=username, pkey=key)
        sftp = paramiko.SFTPClient.from_transport(t)
        f=sftp.file(remote_path,mode='w',bufsize=-1)
        f.write(msg)
        f.close() 
    except Exception as e:
        print(repr(e))
